<?php

namespace App\Task\Update;

use App\Model\User;
use App\Model\UserForbidden;
use Hyperf\Crontab\Annotation\Crontab;

/**
 * 定时修改用户禁言等状态（55分钟）
 * @Crontab(name="UpdateUserStatusTask", rule="55 *\/1 * * *", callback="execute", memo="定时修改用户禁言等状态", singleton=false)
 */
class UpdateUserStatusTask
{
    public function execute()
    {
        log_info(__CLASS__ . "==Start==" . date('Y-m-d H:i:s'));
        $updateUserIds = UserForbidden::getValidUserIds();
        if (empty($updateUserIds)) return;
        //更新状态
        UserForbidden::updateLogStatus();
        //更新用户状态
        $where = [
            'status' => User::STATUS_FORBID
        ];
        User::where($where)->whereIn('id', $updateUserIds)->update(['status' => User::STATUS_OK]);
        log_info(__CLASS__ . "==UpdateUsers:" . json_encode($updateUserIds));
        return;
    }
}
